<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Send Data to Flask</title>
</head>
<body>
<button onclick="sendData([5001, 5002, 5003, 5004, 5005])">Send Data to Ports [5001, 5002, 5003, 5004, 5005]</button>
<button onclick="sendData([5031, 5032, 5033, 5034, 5035])">Send Data to Ports [5031, 5032, 5033, 5034, 5035]</button>

<script>
    var frontCameraId1 = 1; // 初始 camera_id
    var frontCameraId2 = 30; // 初始 camera_id
function sendData1(ports) {
    var data = [
        {
            "path": "D:\\gitee_bytetrack_ketang\\video\\front.mp4",
            "camera_id": frontCameraId1++,
            "person_type": 1
        },
        {
            "path": "D:\\gitee_bytetrack_ketang\\video\\front.mp4",
            "camera_id": frontCameraId1++,
            "person_type": 1
        }
    ];

    // Loop through each port and send data
    ports.forEach(function(port) {
        fetch(`http://10.127.38.150:${port}/send-data`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        })
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            console.log(`Data sent successfully to port ${port}`);
        })
        .catch(error => {
            console.error('There was a problem with the fetch operation:', error);
        });
    });
}

function sendData2(ports) {
    var data = [
        {
            "path": "D:\\gitee_bytetrack_ketang\\video\\back.mp4",
            "camera_id": frontCameraId2++,
            "person_type": 2
        },
        {
            "path": "D:\\gitee_bytetrack_ketang\\video\\back.mp4",
            "camera_id": frontCameraId2++,
            "person_type": 2
        }
    ];

    // Loop through each port and send data
    ports.forEach(function(port) {
        fetch(`http://10.127.38.150:${port}/send-data`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        })
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            console.log(`Data sent successfully to port ${port}`);
        })
        .catch(error => {
            console.error('There was a problem with the fetch operation:', error);
        });
    });
}


</script>

</body>
</html>
